package org.dark.fund.web;


import org.dark.fund.api.IMyFundService;
import org.dark.fund.api.ITokenService;
import org.dark.fund.api.dto.MyFundToday;
import org.dark.fund.common.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wanlh
 * @since 2021-04-29
 */
@RestController
@RequestMapping("/my-fund")
public class MyFundController {

    @Autowired
    private IMyFundService myFundService;

    @Autowired
    private ITokenService tokenService;

    @GetMapping("/index")
    public ApiResult<List<MyFundToday>> loadMyFundToday() {
        String userId = tokenService.get().getUserId();
        return ApiResult.ok(myFundService.getMyFundToday(userId));
    }

    @PostMapping("/add")
    public ApiResult<Boolean> addMyFund(@RequestParam("fundCode") String fundCode) {
        String userId = tokenService.get().getUserId();
        return ApiResult.ok(myFundService.addMyFund(userId, fundCode));
    }

    @DeleteMapping("/remove")
    public ApiResult<Boolean> removeMyFund(@RequestParam("fundCode") String fundCode) {
        String userId = tokenService.get().getUserId();
        return ApiResult.ok(myFundService.removeMyFund(userId, fundCode));
    }
}
